package com.example.mychat.Utils.Permission_verification;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Login_Verification {
    Map<String, Object> LoginList = new HashMap<>();

    /**
     * 获取登陆权限
     * @param id 用户id
     * @param ip 用户端ip地址
     * @return
     */
    public Boolean getVerification(String id, String ip) {
        Boolean flag;
        if (LoginList.containsKey(id)) {
            //获取键对应的值[]--类型是列表
            List<String> mapValue = (List<String>) LoginList.get(id);
            int getlist = mapValue.size();
            if (getlist < 2) {
                addUser(id, ip, mapValue);
                flag = true;
            } else {
                flag = false;
            }

        } else {
            addUser(id, ip);
            flag = true;
        }
        return flag;
    }

    public void addUser(String id, String ip) {
        List<String> listValue = new ArrayList<>();
        listValue.add(ip);
        LoginList.put(id, ip);
    }

    public void addUser(String id, String ip, List<String> value) {
        value.add(ip);
        LoginList.put(id, value);
    }
}
